package com.oa.ylms.apps.business.assess.impl;

import java.util.List;

import com.oa.ylms.apps.business.assess.IItemCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.assess.IItemCategoryDao;
import com.oa.ylms.apps.entity.assess.ItemCategoryValue;

public class ItemCategoryServiceImpl implements IItemCategoryService {

	private IItemCategoryDao dao;
	private ItemCategoryValue itemCategory;

	public int addItemCategory(String categoryName) throws Exception {
		itemCategory.setCategoryName(categoryName);
		itemCategory.setStates(IDEDStates.ENABLE);
		return dao.addItemCategory(itemCategory);
	}

	public String deleteItemCategory(String categoryIds) throws Exception {
		String unDelIds = "";
		String[] arrayCategoryId = categoryIds.split(",");
		for (String categoryIdStr : arrayCategoryId) {
			int categoryId = Integer.parseInt(categoryIdStr);
			itemCategory=queryItemCategoryByCategoryId(categoryId);
			itemCategory.setStates(IDEDStates.DELETE);
			boolean result = dao.editItemCategory(itemCategory);
			if (result == false) {
				unDelIds = categoryId + ",";
				continue;
			}
		}
		return unDelIds;
	}

	public List<ItemCategoryValue> queryAllItemCategory() throws Exception {
		
		return dao.queryAllItemCategory();
	}

	public ItemCategoryValue queryItemCategoryByCategoryId(int categoryId)
			throws Exception {

		return dao.queryItemCategoryByCategoryId(categoryId);

	}

	public IItemCategoryDao getDao() {
		return dao;
	}

	public void setDao(IItemCategoryDao dao) {
		this.dao = dao;
	}

	public ItemCategoryValue getItemCategory() {
		return itemCategory;
	}

	public void setItemCategory(ItemCategoryValue itemCategory) {
		this.itemCategory = itemCategory;
	}

}
